<!DOCTYPE html>
<html>
<head>
<title>req_assign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<script type="text/javascript" src="/codebase/dhtmlxform.js" />
<script type="text/javascript" src="/codebase/dhtmlxgrid.js" />
<style>
</style>
<script>
/*<![CDATA[*/
	var myForm, myGrid,formStructure;
	function doOnLoad() {
		var v=document.getElementById("assign_test_id").innerHTML;
		
		if (myForm) {
			myForm.unload();
			myForm = null;

		}
		//form setup
		myForm = new dhtmlXForm("div_count_form");
		//myForm.loadStruct(formStructure);
		myForm.loadStruct("/test/test_modify_detail_workload_info_onload?test_id="
				+ v);

		myForm.attachEvent("onButtonClick", function(name) {
			if (name = "base_info_save_btn") {
				 var g_plan_workload= count_plan_workload();
				 var g_actual_workload=  count_actual_workload();	
				 var g_test_plan_workload=myForm.getItemValue("test_plan_workload");
				 if(g_plan_workload>g_test_plan_workload){
					 alert("计划工作量合计为【"+g_plan_workload+"】，应小于测试项目要求的计划工作量【"+g_test_plan_workload+"】, \n 请修改录入的相关计划工作量数值");
				 }else{
					 if(g_actual_workload>g_test_plan_workload){
						 alert("实际工作量合计为【"+g_actual_workload+"】，应小于测试项目要求的计划工作量【"+g_test_plan_workload+"】, \n 请修改录入的相关实际工作量数值");
					 }else{
						 var save_value=prepare_save_data();
							var count_rows=myGrid.getRowsNum();	
							var count_columns=myGrid.getColumnCount();				
							
							myGrid.clearAndLoad("/test/test_modify_detail_workload_info_save?test_id="+v+"&count_rows="+count_rows+"&count_columns="+count_columns+"&save_info="+save_value,callback,"json"); 
					 }						 
				 }
				
				
			}
		});
		
		//grid setup
		if (myGrid) {
			myGrid.clearAll(true);
		}
		myGrid = new dhtmlXGridObject("gridbox");
		//myGrid.loadStruct("/common/testmanager/req_list.xml");
		myGrid.setImagePath("/codebase/imgs/");

		myGrid.setHeader("ID,姓名,角色,计划完成日, 实际完成日,计划工作量,实际工作量,测试案例数（联机）,测试案例数（批处理）");
		myGrid.setColumnIds("id,user_name,role,plan_complete_date,actual_complete_date,plan_workload,actual_workload,online_testcase_count,batch_testcase_count");
		myGrid.setInitWidths("25,50,100,100,100,50,50,80,80");
		myGrid.setColAlign("center,left,left,left,left,left,left,left,left");
		myGrid.setColTypes("ro,ed,ed,dhxCalendarA,dhxCalendarA,edn,edn,edn,edn");
		myGrid.setColSorting("str,str,str,str,str,str,str,str,str");
		//myGrid.setColumnIds("first,second");
		var colIndex = myGrid.getColIndexById("plan_workload");
		myGrid.setNumberFormat("0,000.0", colIndex, ".", ",");
		colIndex = myGrid.getColIndexById("actual_workload");
		myGrid.setNumberFormat("0,000.0", colIndex, ".", ",");
		colIndex = myGrid.getColIndexById("online_testcase_count");
		myGrid.setNumberFormat("0,000", colIndex, ".", ",");
		colIndex = myGrid.getColIndexById("batch_testcase_count");
		myGrid.setNumberFormat("0,000", colIndex, ".", ",");
		myGrid.setDateFormat("%Y-%m-%d");
		
		myGrid.xml.top = "mytop";
		myGrid.xml.row = "./myrow";
		//myGrid.enableAutoWidth(true);
		//myGrid.enableAutoHeight(true);
		myGrid.init();
		//myGrid.load("/common/testmanager/test_modify_detail_workload_info_test_data.xml","xml");
		myGrid.load("/test/test_modify_detail_workload_info_grid?test_id=" + v,"json");
		
		myGrid.attachEvent("onCellChanged", function(rId,cInd,nValue){
			   if(cInd==5){
				   var g_plan_workload= count_plan_workload();
				   var g_test_plan_workload=myForm.getItemValue("test_plan_workload");
					 if(parseFloat(g_plan_workload)>parseFloat(g_test_plan_workload)){
						 alert("计划工作量合计为【"+g_plan_workload+"】，应小于测试项目要求的计划工作量【"+g_test_plan_workload+"】, \n 请修改录入的相关计划工作量数值");
					 }else{
				   		myForm.setItemLabel("count_1", "计划工作量合计  ：     "+g_plan_workload+"    人天   ");
				   }
			   }
				if(cInd==6){
					var g_plan=myGrid.cells(rId,5).getValue();
					if(nValue>parseFloat(g_plan)){
						alert("【实际工作量】为"+nValue+",应少于【计划工作量】"+g_plan+"，请修改数值");
					}else{
						var g_actual_workload=  count_actual_workload();	
						 myForm.setItemLabel("count_2",  "实际工作量合计  ：     "+g_actual_workload+"    人天   ");
					}
					
			   }
				if(cInd==7){
					var g_online_testcase_count=  count_online_testcase_count();	
					 myForm.setItemLabel("count_3",  "测试案例数（联机）  ：     "+g_online_testcase_count+"    个   ");
			   }
				if(cInd==8){
					var g_batch_testcase_count=  count_batch_testcase_count();	
					 myForm.setItemLabel("count_4",  "测试案例数（批处理）  ：     "+g_batch_testcase_count+"    个   ");
			   }
			});

	}
		

	var callback=function () {
		if(arguments.length==0){
			alert("保存信息成功");
		}
		else{
			alert("保存信息失败，错误信息："+arguments[1]);
		}
	}
	
	
	function prepare_save_data() {
		var tmp="";		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){	
				for (var i=0; i<myGrid.getColumnCount(); i++){
				//tmp=tmp+j+"_"+i+"=";
				if(i==(myGrid.getColumnCount()-1)){
					tmp=tmp+myGrid.cells(j,i).getValue()+"";	
				}else{
					tmp=tmp+myGrid.cells(j,i).getValue()+",";	
				}
							
			};
			if(j==(myGrid.getRowsNum())){
				tmp=tmp;
			}else{
				tmp=tmp+";";
			}
			
		}
		return tmp;
	}
	
	 function  count_plan_workload(){
		var return_value=0.0;		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){		
			var tmp=myGrid.cells(j,5).getValue();		
			if(tmp!=""){
				if(!isNaN(tmp)){
				var x=parseFloat(tmp);
					return_value=return_value + x;
				}
			}
		}
		return return_value;
	}

	function  count_actual_workload(){
		var return_value=0.0;		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){	
			var tmp=myGrid.cells(j,6).getValue();		
			if(tmp!=""){		
				if(!isNaN(tmp)){
				var x=parseFloat(tmp);
				return_value=return_value +x;
				}
			}
		}
		return return_value;
	}
	
	function  count_online_testcase_count(){
		var return_value=0;		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){	
			var tmp=myGrid.cells(j,7).getValue();		
			if(tmp!=""){		
				if(isNaN(tmp)==false){
				var x=parseFloat(tmp);
				return_value=return_value +x;
				}
			}
		}
		return return_value;
	} 
	
	function  count_batch_testcase_count(){
		var return_value=0;		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){	
			var tmp=myGrid.cells(j,8).getValue();		
			if(tmp!=""){		
				if(isNaN(tmp)==false){
				var x=parseFloat(tmp);
				return_value=return_value +x;
				}
			}
		}
		return return_value;
	} 

	/*]]>*/	
</script>
</head>
<body onload="doOnLoad();">
<div id="assign_test_id" name="assign_test_id" th:text="${test_id}" style="display: none;" > </div>
	<table >
			<tr>
				<td>
					<div id="gridbox" style="width: 700px; height: 200px; background-color: white;"></div>
				</td>
			</tr>
		</table>
	<table>
		<tr>
			<td>
				<div id="form_req_base_info"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="div_count_form"></div>
			</td>
		</tr>
	</table>
</body>
</html>